//
//  RootViewController.m
//  UI21_扩展_自定义抽屉
//
//  Created by dllo on 15/12/8.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "LeftViewController.h"
#import "CenterViewController.h"

@interface RootViewController ()

@property (nonatomic, retain) LeftViewController *leftVC;
@property (nonatomic, retain) CenterViewController *centerVC;

@end

@implementation RootViewController

- (void)dealloc
{
    [_leftVC release];
    [_centerVC release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor blackColor];
    
    self.leftVC = [[LeftViewController alloc] init];
    [self addChildViewController:self.leftVC];
    self.leftVC.view.frame = CGRectMake(-self.view.frame.size.width / 2.0, 0, self.view.frame.size.width / 2.0, self.view.frame.size.height);
    [self.view addSubview:self.leftVC.view];
    
    
//    self.centerVC = [[CenterViewController alloc] init];
//    UINavigationController *centerNC = [[UINavigationController alloc] initWithRootViewController:self.centerVC];
    
    CenterViewController *centerVC = [[CenterViewController alloc] init];
    self.centerVC = [[UINavigationController alloc] initWithRootViewController:centerVC];
    
    [self addChildViewController:self.centerVC];
    self.centerVC.view.frame = self.view.frame;
    [self.view addSubview:self.centerVC.view];
    
    
//    UIScreenEdgePanGestureRecognizer *edgeGR = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(edgeAction)];
//    edgeGR.edges = UIRectEdgeLeft;
//    [self.view addGestureRecognizer:edgeGR];
//    [edgeGR release];
    
    UISwipeGestureRecognizer *swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeAction)];
    swipeGR.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:swipeGR];
    [swipeGR release];
    
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [self.view addGestureRecognizer:tapGR];
    [tapGR release];
    
}

- (void)tapAction
{
    [UIView animateWithDuration:0.5 animations:^{
        
        self.leftVC.view.frame = CGRectMake(-self.view.frame.size.width / 2.0, 0, self.view.frame.size.width / 2.0, self.view.frame.size.height);
        
        self.centerVC.view.frame = self.view.frame;
        
    }];
}

- (void)swipeAction
{
    [UIView animateWithDuration:0.5 animations:^{
        
        self.leftVC.view.frame = CGRectMake(0, 0, self.view.frame.size.width / 2.0, self.view.frame.size.height);
        
//        self.centerVC.view.frame = CGRectMake(self.view.frame.size.width / 2.0, 0, self.view.frame.size.width, self.view.frame.size.height);
        
        self.centerVC.view.frame = CGRectMake(self.view.frame.size.width / 2.0, 80, self.view.frame.size.width / 2.0, self.view.frame.size.height - 160);
        
    }];
}

- (void)edgeAction
{
    NSLog(@"asdf");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
